package cn.asiawu.springboot.controller;

import cn.asiawu.springboot.common.Result;
import cn.asiawu.springboot.entity.User;
import cn.asiawu.springboot.service.UserService;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.Quarter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

//折线图和图表的交互
@RestController
@RequestMapping("/echarts")
public class EchartsController {
    @Autowired
    private UserService userService;

    //测试数据
//    @GetMapping("/example")
//    public Result get() {
//        List<String> listX=new ArrayList<>(Arrays.asList("Mon"));
//        List<Integer> listY=userService.getDataInAWeek();
//        return Result.success(listY);
//    }

    //注册人数折线图
    @GetMapping("/registerusers")
    public Result registerUsers() {
        int q1=0,q2=0,q3=0,q4=0;
        List<User> list=userService.list();
        for (User user : list) {
            Date createTime=user.getCreatetime();
            Quarter quarter = DateUtil.quarterEnum(createTime);
            switch (quarter) {
                case Q1:q1++;break;
                case Q2:q2++;break;
                case Q3:q3++;break;
                case Q4:q4++;break;
                default:break;
            }
        }
        return Result.success(Arrays.asList(q1,q2,q3,q4));
    }
}
